# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
import pymysql

class JdSpiderPipeline(object):
    def process_item(self, item, spider):
        # config = {
        #     'host': "127.0.0.1"
        #     , 'port': 3306
        #     , 'user': 'root'
        #     , 'password': ''
        #     , 'db': 'test'
        #     , 'charset': 'utf8'
        #     , 'cursorclass': pymysql.cursors.DictCursor
        # }
        # connection = pymysql.connect(**config)
        # try:
        #     with connection.cursor() as cursor:
        #         # 执行sql语句，插入记录
        #         sql = 'INSERT INTO jd_bra_url (url) VALUES (%s)'
        #         print(sql)
        #         cursor.execute(sql, (item["url"]))
        #     # 没有设置默认自动提交，需要主动提交，以保存所执行的语句
        #     connection.commit()
        # finally:
        #     connection.close()
        return item
